home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / What's New? / Software Development Kits / Mac OS USB DDK / MacOS USB DDK 1.0b4 / NeptuneDDK / Examples / KeyboardModule / KeyboardModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-26  |  3.8 KB  |  121 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        KeyboardModuleHeader.c
  3.  
  4.     Contains:    Keyboard Module Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17. #include "KeyboardModule.h"
  18. #include "KeyboardModuleVersion.h"
  19.  
  20. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  21. static     OSStatus     KeyboardModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  22. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  23.  
  24. extern    usbKeyboardPBStruct myKeyboardPB;
  25.  
  26. //------------------------------------------------------
  27. //
  28. //    This is the driver description structure that the expert looks for first.
  29. //  If it's here, the information within is used to match the driver
  30. //  to the device whose descriptor was passed to the expert.
  31. //    Information in this block is also used by the expert when an
  32. //  entry is created in the Name Registry.
  33. //
  34. //------------------------------------------------------
  35. USBDriverDescription    TheUSBDriverDescription = 
  36. {
  37.     // Signature info
  38.     kTheUSBDriverDescriptionSignature,
  39.     kInitialUSBDriverDescriptor,
  40.     
  41.     // Device Info
  42.     0,                                        // vendor = not device specific
  43.     0,                                        // product = not device specific
  44.     0,                                        // version of product = not device specific
  45.     kUSBKeyboardInterfaceProtocol,                // protocol = not device specific
  46.     
  47.     // Interface Info    (* I don't think this would always be required...*)                
  48.     0,                                        // Configuration Value
  49.     0,                                        // Interface Number
  50.     kUSBHIDInterfaceClass,                    // Interface Class
  51.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  52.     kUSBKeyboardInterfaceProtocol,                // Interface Protocol
  53.         
  54.     
  55.     // Driver Info
  56.     "\pUSBHIDKeyboardModule",                // Driver name for Name Registry
  57.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  58.     kUSBBootInterfaceSubClass,                // Device Subclass 
  59.     kKBDHexMajorVers, 
  60.     kKBDHexMinorVers, 
  61.     kKBDCurrentRelease, 
  62.     kKBDReleaseStage,                        // version of driver
  63.     
  64.     // Driver Loading Info
  65.     kUSBProtocolMustMatch                    // Flags 
  66. };
  67.  
  68. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  69. {
  70.     kClassDriverPluginVersion,                // Version of this structure
  71.     0,                                        // Hardware Validation Procedure
  72.     KeyboardModuleInitialize,                    // Initialization Procedure
  73.     KeyboardInterfaceInitialize,                // Interface Initialization Procedure
  74.     KeyboardModuleFinalize,                    // Finalization Procedure
  75.     0,                                        // Driver Notification Procedure
  76. };
  77.     
  78.  
  79.     
  80. // Initialization function
  81. // Called upon load by Expert
  82. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  83. {
  84. #pragma unused (busPowerAvailable)
  85.     DriverEntry(device, pDesc);
  86.     return (OSStatus)noErr;
  87. }
  88.  
  89. // Interface Initialization Initialization function
  90. // Called upon load by Expert
  91. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  92. {
  93.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  94.     return (OSStatus)noErr;
  95. }
  96.  
  97.  
  98.  
  99. // Termination function
  100. // Called by Expert when driver is being shut down
  101. static OSStatus KeyboardModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  102. {
  103. #pragma unused (pDesc)
  104.  
  105. OSStatus myErr;
  106.  
  107.     if (myKeyboardPB.pFullConfigDescriptor != nil)
  108.     {
  109.         myKeyboardPB.pb.usbReference = theDeviceRef;
  110.         myKeyboardPB.pb.pbVersion = kUSBCurrentPBVersion;
  111.         myKeyboardPB.pb.usbFlags = 0;
  112.         myKeyboardPB.pb.usbRefcon = 0;             
  113.         myKeyboardPB.pb.usbBuffer = myKeyboardPB.pFullConfigDescriptor;        
  114.         myKeyboardPB.pb.usbCompletion = (USBCompletion)-1;
  115.         
  116.         myErr = USBDeallocMem(&myKeyboardPB.pb);
  117.     };
  118.     return (OSStatus)noErr;
  119. }
  120.  
  121.